package com.jxj.mapper;

import com.jxj.pojo.fankui;
import com.jxj.pojo.student;
import com.jxj.pojo.studentrunning;
import com.jxj.pojo.user;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface mapperUser {

    @Insert("INSERT INTO user (username, password) VALUE (#{username}, #{password})")
    int adduser(@Param("username") String username, @Param("password") String password);

    @Select("SELECT s.student_id, s.name, r.sKM, r.starttime, r.endtime, r.Aspeed, r.luxian, r.youxiao, r.weiji " +
            "FROM run r INNER JOIN students s ON r.student_id = s.student_id " +
            "ORDER BY s.student_id ASC")
    List<studentrunning> getStudentList(String text);

    @Update("UPDATE run SET weiji = weiji + 1, youxiao = '否' WHERE student_id = #{click}")
    int zuifei(int click);

    @Update("UPDATE running SET YKM = 0 WHERE student_id = #{click}")
    int cleanu(int click);

    @Delete("DELETE FROM run WHERE student_id = #{click}")
    int cleand(int click);

    @Update("UPDATE running SET YKM = null, BKM = null, alltime = null, avgspeed = null, NOKM = null, hei = true WHERE student_id = #{click}")
    int addheiD(int click);

    @Delete("DELETE FROM run WHERE student_id = #{click}")
    int addheiU(int click);

    @Insert("INSERT INTO students (student_id, name, age, major, grade) VALUES (#{a}, #{b}, #{c}, #{d}, #{e})")
    int addI1(@Param("a") Integer a,@Param("b") String b,@Param("c") Integer c,@Param("d") String d,@Param("e") String e);

    @Insert("INSERT INTO running (student_id) VALUES (#{a})")
    int addI2(Integer a);

    @Update("UPDATE students SET student_id = #{a}, name = #{b}, age = #{c}, major = #{d}, grade = #{f} WHERE student_id = #{id}")
    int changeU1(@Param("a") int a, @Param("b") String b, @Param("c") int c, @Param("d") String d, @Param("f") String f, @Param("id") int id);

    @Update("UPDATE running SET student_id = #{a}, BKM = #{b} WHERE student_id = #{id}")
    int changeU2(@Param("a")int a, @Param("b")int b, @Param("id")int id);

    @Update("UPDATE fankui SET status = '是' WHERE student_id = #{row}")
    int chuli(int row);

    @Select("SELECT password FROM user WHERE username = #{username}")
    List<user> getuserList(String username);

    @Select("SELECT * FROM students INNER JOIN running ON students.student_id = running.student_id ORDER BY students.student_id ASC")
    List<student> getstudentList();

    @Delete("DELETE FROM students WHERE student_id = #{click}")
    int deletestu1(int click);

    @Delete("DELETE FROM running WHERE student_id = #{click}")
    int deletestu2(int click);

    @Select("SELECT hei FROM running WHERE student_id = #{click}")
    boolean hei(int click);

    @Select("SELECT s.student_id, s.name, f.time, f.thing, f.status FROM students s INNER JOIN fankui f ON s.student_id = f.student_id ORDER BY f.time ASC")
    List<fankui> fankuiList();


    @Select("SELECT user.password from user where username=#{username}")
    String xianshi(String username);
}
